package clang.control;

import clang.data.VarType;
import clang.data.Variable;

public class VariableDefinition implements CodeElement {

	private String name;
	private VarType type;
	private boolean init = false;
	private double val = 0.0;
	
	public VariableDefinition(String name, VarType type)
	{
		this.name = name;
		this.type = type;
	}
	
	public VariableDefinition(String name, VarType type, double val)
	{
		this.name = name;
		this.type = type;
		this.val = val;
		init = true;
	}
	
	@Override
	public void execute() throws Exception {
		Variable v = new Variable(name, type);
		if(init)
			v.setData(val);
		ExecutionThread.get().getCurrentBlock().defineVariable(v);
	}

}
